# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time      :2022/8/10 0010 19:21
# @Author    :jiaxuesong


#导包
import unittest

from hight_interface_test01.common.readExcle import ReadExcle
from hight_interface_test01.common.log import logger
from hight_interface_test01.common.configHttp import ConfigHttp
from ddt import ddt, data, unpack
from hight_interface_test01.common.writeExcle import WriteExcle
from hight_interface_test01.common.preSolve import PreSolve

# 实例化获取readExcle
readEx = ReadExcle()
readEx_open = readEx.read()
print(readEx_open)
@ddt
class TesrCase(unittest.TestCase):
    @data(*readEx_open)
    @unpack
    def test_case(self, id, interfaceUrl, name, method, value, header, rely, caseid, expect, real, status):
        # 转换数据格式
        value = eval(value)
        expect = int(expect)
        header = eval(header)

        # 执行前置用例
        # 进行实例化
        # 调用实例化方法
        ps = PreSolve(readEx_open)
        header, value = ps.presolve(id)
        # 实例化方法调用
        res = ConfigHttp(interfaceUrl, method, eval(value), eval(header))
        re = res.get_method()

        # 设置返回值格式
        re_dict = re.json()
        print(re_dict)
        real = re_dict['errorCode']
        try:
            if real == expect:
                status = 'pass'
            else:
                status = 'fail'
            # 实例化写入方法
            we = WriteExcle()
            we.write(int(id), 9, real, status)
        except Exception as msg:
            print(f'接口调用报错{msg}')
            raise
        self.assertEqual(real, expect, '接口不通过！')


if __name__ == '__main__':
    unittest.main(verbosity=2)








